#include "handy/handy/handy.h"
#include <algorithm>
#include <stdio.h>
#include <string>
#include <stdint.h>
#include <arpa/inet.h>
#include "common.h"
#include "xudp.pb.h"

using std::string;
using namespace handy;
int main() {
	setloglevel("INFO");
  setlogfile("test_server_udp");
	EventBase base;
	Signal::signal(SIGINT, [&] { base.exit(); });

	UdpServerPtr s = handy::UdpServer::startServer(&base, "", SERVER_PORT);
	exitif(s == NULL, "start udp server failed");
	s->onMsg([](const UdpServerPtr& p, Buffer buf, Ip4Addr peer) {
		xmsg m;
		m.ParseFromArray(buf.data(), buf.size());	
		info("id:%d,time:%ld", m.id(),util::timeMilli());
	});
	base.loop();
	info("program exited");
}
